<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ page import="net.comm.common.Message"%>

<%
	String _action_ = (String)request.getAttribute(ACTION);
	/**
	 *  分页使用的jsp页面,分页信息从request的attribute中读取
	 */
	int _pos_ = 0;
	int _total_ = 0;
	int _currPage_ = 1;
	int _sumPage_ = 0;
    String _direction_ = "";
	
	net.comm.page.PageCtr _page_ = (net.comm.page.PageCtr)request.getAttribute("_page_");
	if(_page_ != null)
	{
		_pos_		= _page_.getPos();
		_currPage_  = _page_.getCurPage();
		_total_     = _page_.getTotalNum();
		_sumPage_   = _page_.getTotalPages();
		_direction_ = _page_.getDirection();
	}

	if(_page_ != null) 
    {
%>

<script>

     function StringBuffer()//使用构造函数
     {
        this._strings_=new Array;
     }
     StringBuffer.prototype.append=function (str)//使用原型定义函数属性
     {
		this._strings_.push(str);
     }
     StringBuffer.prototype.toString=function ()//使用原型定义函数属性
     {
		return this._strings_.join("");
     }

	 var buffer=new StringBuffer();//使用类

	/**
	 * 遍历form 把上一页面的查询条件保存到URL中
	 */
	 //遍历INPUT
  var inputs = document.forms["theForm"].tags("INPUT");    //得到所有的input，包含文本输入框，和按钮

  var qryname;
  var qryvalue;
  for(var i=0; i<inputs.length; i++)   //查找一个输入框
  {  
      if(inputs[i].name.indexOf("qry") > -1)
      {  
		qryname = inputs[i].name;
		qryvalue = inputs[i].value;
		if(qryvalue !="" && qryvalue != 0 && qryvalue != 0.0){
			buffer.append("&");
			buffer.append(qryname);
			buffer.append("=");
			buffer.append(qryvalue);
		}
      }
      if(inputs[i].name.indexOf("checkbox") > -1)
      {  
		qryname = inputs[i].name;
		qryvalue = inputs[i].value;
		if(inputs[i].checked){
			buffer.append("&");
			buffer.append(qryname);
			buffer.append("=");
			buffer.append(qryvalue);
		}
      }
  }
  //遍历select
  var inputs = document.forms["theForm"].tags("SELECT");    //得到所有的SELECT，包含文本输入框，和按钮
  for(var i=0; i<inputs.length; i++)   //查找一个输入框
  {  
      if(inputs[i].name.indexOf("qry") > -1) 
      {  
					qryname = inputs[i].name;
					qryvalue = inputs[i].value;
					if(qryvalue !="" && qryvalue != 0 && qryvalue != 0.0){

						buffer.append("&");
						buffer.append(qryname);
						buffer.append("=");
						buffer.append(qryvalue);
					}
      }
  }
//	alert(buffer.toString());
</script>
<script>

	var form = document.forms["theForm"];

	var formaction = form.action;
	//formaction.replace(".", "");

	//alert(formaction);

	<%
		if(_action_ != null) {
	%>
		form['<%=ACTION%>'].value = '<%=_action_%>';
	<%
		}
	%>
	</script>
      <div align="center"> 
            <%=Message.ZG%>【<%=_sumPage_%>】&nbsp;<%=Message.Y%> &nbsp;
        <%
            if(_currPage_ > 1) {
			int _prevPage_ = _currPage_ - 1;
        %>
            <a id ="gotoFirstLabel" href='javascript:gotoFirstPage();'><%=Message.FIRST%></a>
            <a id="gotoPreLabel" href='javascript:gotoPrePage();'><%=Message.PREV%></a>
				<!---->
				<script>
				document.getElementById("gotoFirstLabel").href=formaction+"/<%=_action_%>" + "/cP1/dN/" + buffer.toString();

				document.getElementById("gotoPreLabel").href=formaction+"/<%=_action_%>" + "/cP<%=_prevPage_%>/dP/" + buffer.toString();
				</script>
				
        <% } %>
		<!--增加显示1、2、3、4、5、6、7、8、9、10页-->
		<%
			int _dispage_=0;
			int _startpage_ = 1;
			if(_currPage_ >= 10){

				_startpage_ = _currPage_/10 * 10 ;
			}
			_dispage_ =  _startpage_ + 9 ;
			if( _dispage_ > _sumPage_){

				_dispage_ =  _sumPage_ ;
			}

			for(int PAGENO=_startpage_ ; PAGENO <= _dispage_ ; PAGENO++){
		%>
            <a id="<%=PAGENO%>" href='javascript:gotoPageNo(<%=PAGENO%>);'>
			<%
			if(PAGENO == _currPage_){
			%>
			<FONT color=red><%=PAGENO%></FONT>
			<%}else{%>
			<%=PAGENO%>
			<%}%>
			</a>
				<!---->
				<script>
				document.getElementById("<%=PAGENO%>").href=formaction+"/<%=_action_%>" + "/cP<%=PAGENO%>/dN/" + buffer.toString();
				</script>
				<%}%>
				<!---->
				<%
            if(_currPage_ < _sumPage_) {
        %>
            <a id="gotoNextLabel" href='javascript:gotoNextPage();'><%=Message.NEXT%></a>

            <a id="gotoLastLabel" href='javascript:gotoEndPage();'><%=Message.LAST%></a>
				<!---->
				<script>
					var nextpage = <%=_currPage_%>+1;
					document.getElementById("gotoNextLabel").href=formaction+"/<%=_action_%>" + "/cP" + nextpage + "/dN/" + buffer.toString();
					document.getElementById("gotoLastLabel").href=formaction+"/<%=_action_%>" + "/cP<%=_sumPage_%>/dL/"+ buffer.toString();
				</script>
        <% }%>
		&nbsp;跳转&nbsp;<select name="select" style="height:18px;line-height:18px;font-size:12px" onchange="javascript:gotoPageNo(this.value);">
		<%
			for(int PAGENO=1; PAGENO <= _sumPage_ ; PAGENO++){
		%>
			<option value="<%=PAGENO%>"><%=PAGENO%></option>
		<%}%>
		</select>&nbsp;页
        
		</div>
<% }
    //转义字符串中的"字符成html对应的字符&quot;
    String _key_ = net.comm.util.StringUtil.getValue((String)request.getAttribute("_key_"));
    String _last_key_ = net.comm.util.StringUtil.getValue((String)request.getAttribute("_lastkey_"));
    _key_ = net.comm.util.StringUtil.replaceStrAll(_key_ , "\"" , "&quot;");
    _last_key_ = net.comm.util.StringUtil.replaceStrAll(_last_key_ , "\"" , "&quot;");
%>

<input type="hidden" name="pos"			value="<%=_pos_%>">
<input type="hidden" name="currPage"    value="<%=_currPage_%>">
<input type="hidden" name="direction"   value="<%=_direction_%>">
<input type="hidden" name="_key_"       value="<%=_key_%>">
<input type="hidden" name="_lastkey_"   value="<%=_last_key_%>">

<script>
var form = document.forms["theForm"];

/**
 * 使用lastKey设置当前key值
 */
function resetKey()
{
    form._key_.value = form._lastkey_.value;
}

/**
 * 下一页
 */
function gotoNextPage()
{

		form.currPage.value=<%=_currPage_%>+1;
    form.direction.value="N";
   
<%if(_action_ != null) {
%>
    form['<%=ACTION%>'].value = '<%=_action_%>';
<%}%>
    try {
        disableBtn();
    } catch(ex){}

    form.submit();
}

/**
 * 首页
 */
function gotoFirstPage() 
{
    form.currPage.value="1";
    form.direction.value="N";
    form._key_.value= "";

<%
    if(_action_ != null) {
%>
    form['<%=ACTION%>'].value = '<%=_action_%>';
<%
    }
%>
    try {
        disableBtn();
    } catch(ex){}


    form.submit();
}

/**
 * 尾页
 */
function gotoEndPage() 
{
    form.currPage.value=<%=_sumPage_%>;
    form.direction.value="L";

<%
    if(_action_ != null) {
%>
    form['<%=ACTION%>'].value = '<%=_action_%>';
<%
    }
%>

    try {
        disableBtn();
    } catch(ex){}

    form.submit();
}

/**
 * 上一页
 */
function gotoPrePage()
{
    if(<%=_currPage_%> -1 < 1) {
        form.currPage.value=1;
    } else{
        form.currPage.value=<%=_currPage_%>-1;
    }
    form.direction.value="P";

<%
    if(_action_ != null) {
%>
    form['<%=ACTION%>'].value = '<%=_action_%>';
<%
    }
%>
    try {
        disableBtn();
    } catch(ex){}

    form.submit();
}
/**
 * 指定页
 */
function gotoPageNo(pageno)
{
    form.currPage.value=pageno;
    form.direction.value="N";

<%
    if(_action_ != null) {
%>
    form['<%=ACTION%>'].value = '<%=_action_%>';
<%
    }
%>
    try {
        disableBtn();
    } catch(ex){}

    form.submit();
}
</script>